package com.dsl.quartz;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Value;

import java.io.File;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;


/**
 * @Description TODO
 * @Author dsl
 * @Date 2024/9/21 下午9:59
 * @Version 1.0
 */
@Component
public class WKImageDeleteJob implements Job {

    private static final Logger logger = LoggerFactory.getLogger(WKImageDeleteJob.class);

    @Value("${wk.image.storage}")
    private String wkImageStorage;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        File[] files = new File(wkImageStorage).listFiles();
        if(files == null || files.length == 0){
            logger.info("没有wk图片，任务取消！");
            return;
        }

        for(File file: files){
            //删除一分钟前创建的图片
            if(System.currentTimeMillis() - file.lastModified() > 60 * 1000){
                logger.info("删除wk图片{}", file.getName());
                file.delete();
            }
        }
    }
}
